<?php
/**
 * Created by PhpStorm.
 * Script Name: MpBase.php
 * Create: 2023/2/28 19:02
 * Description:
 * Author: fudaoji<fdj@kuryun.cn>
 */

namespace plugin\wechat\app\tenant\controller;


use plugin\wechat\app\TenantController;

class MpBase extends TenantController
{

    public function __construct()
    {
        parent::__construct();
    }

    public function __get($name)
    {
        $request = \request();
        switch ($name){
            case 'mpInfo':
                return $request->mpInfo;
                break;
        }
        return null;
    }

    /**
     * 获取当前操作公众号的信息
     * @param null $key
     * @return mixed|null
     * Author: fudaoji<fdj@kuryun.cn>
     */
    protected function getCurrentMp($key = null){
        $data = request()->mpInfo;
        return $key!==null ? $data[$key] : $data;
    }

    /**
     * 公众号id条件
     * @param string $alias
     * @param array $mp_info
     * @return array
     * Author: fudaoji<fdj@kuryun.cn>
     */
    public function mpIdWhere($alias = '', $mp_info = []){
        $alias = $alias ? $alias.'.' : '';
        $mp_info = empty($mp_info) ? $this->getCurrentMp() : $mp_info;
        return [$alias . 'mp_id', '=', $mp_info['id']];
    }
}